﻿
using AutoMapper;
using OP10.AutoMapper;
using OP10.Views.ST02;
using OP10.Views.ST04.Devices;
using OP10.Views.ST13;

namespace OP10.Extensions
{
    public static class ContainerExtensions
    {
        public static void AddViews(this IContainerRegistry services)
        {

            //新增部分
            services.Add<MainWindow, MainWindowViewModel>(AppViews.MainWindow);
            services.Add<AllStationView, AllStationViewModel>(AppViews.AllStationView);
            services.Add<MenuView, MenuViewModel>(AppViews.MenuView);
            services.Add<AlarmsManagerView, AlarmsManagerViewModel>(AppViews.AlarmsManagerView);
            services.Add<AlarmsHistoryView, AlarmsHistoryViewModel>(AppViews.AlarmsHistoryView);
            services.Add<PingBiView, PingBiViewModel>(AppViews.PingBiView);
            services.Add<IOMonitorView, IOMonitorViewModel>(name: AppViews.IOMonitorView);
            services.Add<ProductStatisticView, ProductStatisticViewModel>(AppViews.ProductStatisticView);
            services.Add<LifeControlView, LifeControlViewModel>(AppViews.LifeControlView);
            services.Add<ContinuousNgView, ContinuousNgViewModel>(AppViews.ContinuousNgView);
            services.Add<CycleTimeStatisticView, CycleTimeStatisticViewModel>(AppViews.CycleTimeStatisticView);
            services.Add<ST01View, ST01ViewModel>(AppViews.ST01View);
            services.Add<ST02View, ST02ViewModel>(AppViews.ST02View);
            services.Add<ST03View, ST03ViewModel>(AppViews.ST03View);
            services.Add<ST04View, ST04ViewModel>(AppViews.ST04View);
            services.Add<ST05View, ST05ViewModel>(AppViews.ST05View);
            services.Add<ST06View, ST06ViewModel>(AppViews.ST06View);
            services.Add<ST07View, ST07ViewModel>(AppViews.ST07View);
            services.Add<ST08View, ST08ViewModel>(AppViews.ST08View);
            services.Add<ST09View, ST09ViewModel>(AppViews.ST09View);
            services.Add<ST10View, ST10ViewModel>(AppViews.ST10View);
            services.Add<ST11View, ST11ViewModel>(AppViews.ST11View);
            services.Add<ST12View, ST12ViewModel>(AppViews.ST12View);
            services.Add<ST13View, ST13ViewModel>(AppViews.ST13View);

            services.Add<ST01CyManagerView, ST01CyManagerViewModel>(AppViews.ST01CyManagerView);
            services.Add<ST02CyManagerView, ST02CyManagerViewModel>(AppViews.ST02CyManagerView);
            services.Add<ST01DeviceManagerView, ST01DeviceManagerViewModel>(AppViews.ST01DeviceManagerView);
            services.Add<ST03CyManagerView, ST03CyManagerViewModel>(AppViews.ST03CyManagerView);
            services.Add<ST03CCDManagerView, ST03CCDManagerViewModel>(AppViews.ST03CCDManagerView);
            services.Add<ST04CyManagerView, ST04CyManagerViewModel>(AppViews.ST04CyManagerView);
            services.Add<ST04DeviceManagerView, ST04DeviceManagerViewModel>(AppViews.ST04DeviceManagerView);
            services.Add<ST04BridgeWireRollServoView, ST04BridgeWireRollServoViewModel>(AppViews.ST04BridgeWireRollServoView);
            services.Add<ST04BridgeWireTowerServoView, ST04BridgeWireTowerServoViewModel>(AppViews.ST04BridgeWireTowerServoView);
            services.Add<ST04ElectrodeNeedleConfigView, ST04ElectrodeNeedleConfigViewModel>(AppViews.ST04ElectrodeNeedleConfigView);
            services.Add<ST04ElectrodeNeedleOperateView, ST04ElectrodeNeedleOperateViewModel>(AppViews.ST04ElectrodeNeedleOperateView);
            services.Add<ST04LeftMotorCheckView, ST04LeftMotorCheckViewModel>(AppViews.ST04LeftMotorCheckView);
            services.Add<ST04LeftMotorOperateView, ST04LeftMotorOperateViewModel>(AppViews.ST04LeftMotorOperateView);
            services.Add<ST04RightMotorCheckView, ST04RightMotorCheckViewModel>(AppViews.ST04RightMotorCheckView);
            services.Add<ST04RightMotorOperateView, ST04RightMotorOperateViewModel>(AppViews.ST04RightMotorOperateView);
            services.Add<ST04WeldCheckView, ST04WeldCheckViewViewMdoel>(AppViews.ST04WeldCheckView);
            services.Add<ST04WeldParameterView, ST04WeldParameterViewModel>(AppViews.ST04WeldParameterView);
            services.Add<ST04WeldTestView, ST04WeldTestViewModel>(AppViews.ST04WeldTestView);
            services.Add<ST04XAxisServoView, ST04XAxisServoViewModel>(AppViews.ST04XAxisServoView);
            services.Add<ST04YAxisLeftServoView, ST04YAxisLeftServoViewModel>(AppViews.ST04YAxisLeftServoView);
            services.Add<ST04YAxisRightServoView, ST04YAxisRightServoViewModel>(AppViews.ST04YAxisRightServoView);
            services.Add<ST05CyManagerView, ST05CyManagerViewModel>(AppViews.ST05CyManagerView);
            services.Add<ST05CCDManagerView, ST05CCDManagerViewModel>(AppViews.ST05CCDManagerView);
            services.Add<ST06CyManagerView, ST06CyManagerViewModel>(AppViews.ST06CyManagerView);
            services.Add<ST06TestMachineManagerView, ST06TestMachineManagerViewModel>(AppViews.ST06TestMachineManagerView);
            services.Add<ST07CyManagerView, ST07CyManagerViewModel>(AppViews.ST07CyManagerView);
            services.Add<ST08CyManagerView, ST08CyManagerViewModel>(AppViews.ST08CyManagerView);
            services.Add<ST09CyManagerView, ST09CyManagerViewModel>(AppViews.ST09CyManagerView);
            services.Add<ST10CyManagerView, ST10CyManagerViewModel>(AppViews.ST10CyManagerView);
            services.Add<ST11CyManagerView, ST11CyManagerViewModel>(AppViews.ST11CyManagerView);
            services.Add<ST12CyManagerView, ST12CyManagerViewModel>(AppViews.ST12CyManagerView);
            services.Add<ST13CyManagerView, ST13CyManagerViewModel>(AppViews.ST13CyManagerView);
            services.Add<ST13DeviceManagerView, ST13DeviceManagerViewModel>(AppViews.ST13DeviceManagerView);


            services.Add<LoginView, LoginViewModel>(AppViews.LoginView);
        }


        public static void AddAutoMapper(this IContainerRegistry services)
        {
            services.RegisterSingleton<IAutoMapperProvider, AutoMapperProvider>();
            services.Register(typeof(IMapper), GetMapper);
        }


        #region 私有方法

        private static void Add<TView, TViewModel>(this IContainerRegistry containerRegistry, string name = null)
        {
            containerRegistry.RegisterForNavigation<TView, TViewModel>(name);
        }

        private static IMapper GetMapper(IContainerProvider container)
        {
            var provider = container.Resolve<IAutoMapperProvider>();
            return provider.GetMapper();
        }

        #endregion
    }
}
